package com.tianji.promotion.service.impl;

import com.tianji.promotion.domain.po.CouponScope;
import com.tianji.promotion.mapper.CouponScopeMapper;
import com.tianji.promotion.service.ICouponScopeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 优惠券作用范围信息 服务实现类
 * </p>
 *
 * @author rui
 * @since 2024-08-05
 */
@Service
public class CouponScopeServiceImpl extends ServiceImpl<CouponScopeMapper, CouponScope> implements ICouponScopeService {
    @Override
    public  Map<Integer, List<Long>> getSpecificByCouponId(Long couponId) {
        List<CouponScope> list = lambdaQuery()
                .eq(CouponScope::getCouponId, couponId)
                .list();
        Map<Integer, List<Long>> bizMap = list.stream()
                .collect(Collectors.groupingBy(
                        CouponScope::getType, // 按 CouponScope 的 type 属性进行分组
                        Collectors.mapping(
                                CouponScope::getBizId, // 提取 CouponScope 的 bizId 属性
                                Collectors.toList() // 将提取的 bizId 收集到 List<Long> 中
                        )
                ));
        return bizMap;
    }
}
